package com.wordpress.thenonsensetechlogs.weathermonitor.displays;

import com.wordpress.thenonsensetechlogs.weathermonitor.station.Observable;
import com.wordpress.thenonsensetechlogs.weathermonitor.station.Observer;
import com.wordpress.thenonsensetechlogs.weathermonitor.station.WeatherMonitoringStation;

public class CurrentConditionsDisplay implements Observer, DisplayElement {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.wordpress.thenonsensetechlogs.weathermonitor.station.Observer#update
	 * (com.wordpress.thenonsensetechlogs.weathermonitor.station.Observable)
	 */
	public void update(Observable observable) {

		String temperature = ((WeatherMonitoringStation) observable).getTemperature();
		String pressure = ((WeatherMonitoringStation) observable).getPressure();
		String humidity = ((WeatherMonitoringStation) observable).getHumidity();

		display(temperature, pressure, humidity);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.wordpress.thenonsensetechlogs.weathermonitor.displays.DisplayElement
	 * #display(java.lang.String, java.lang.String, java.lang.String)
	 */
	public void display(String temperature, String pressure, String humidity) {

		System.out.println("Temperature : " + temperature + " Pressure : " + pressure + " Humidity : " + humidity);
	}
	
	
	public static void main(String[] args) {
		
		WeatherMonitoringStation weatherMonitoringStation = new WeatherMonitoringStation();
		CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay();
		
		System.out.println("Registering...");
		weatherMonitoringStation.registerObserver(currentConditionsDisplay);
		System.out.println("Changing Measurements....");
		weatherMonitoringStation.measurementsChanged();
		System.out.println("De Registering....");
		weatherMonitoringStation.deRegisterObserver(currentConditionsDisplay);
		System.out.println("Changing Measurements....");
		weatherMonitoringStation.measurementsChanged();
	}

}
